﻿using Glue;
using Xunit;

namespace GlueTests.RelationFactoryTests
{
    public class When_right_property_is_read_only
    {
        private readonly Mapping<DomainPerson, GuiPerson> mapping;

        public class DomainPerson { public int Id { get; set; } }
        public class GuiPerson { public int Id { get; private set; } }

        public When_right_property_is_read_only()
        {
            mapping = new Mapping<DomainPerson, GuiPerson>();
        }

        [Fact]
        public void Should_not_allow_relating_twoways()
        {
            Assert.Throws(typeof(GlueException), ()=> mapping.Relate(domain=>domain.Id,gui=>gui.Id));
        }

        [Fact]
        public void Should_allow_relating_TowardsLeft()
        {
            mapping.RelateTowardsLeft(domain => domain.Id, gui => gui.Id);
        }

        [Fact]
        public void Should_not_allow_relating_TowardsRight()
        {
            Assert.Throws(typeof(GlueException), ()=>mapping.RelateTowardsRight(domain => domain.Id, gui => gui.Id));
        }
    }
}
